import time
from structs import TickData
import pyctpmdif
import structs

#define sleep function as micro-seconde sleeper
usleep = lambda x: time.sleep(x/1000000.0)

#must call reg_struct and profile before receive
pyctpmdif.reg_struct(structs)
i = pyctpmdif.profile('./ctpif.conf')
print 'get configure file result is', i

#
#trading time
#start function will wait for 3 seconds then connect to CTP MarketData Server
#you can prepare receive data in this time
#i = pyctpmdif.start();
#print 'receiver thread id is', i   #zero is no error
#

#
#non-trading time
#run this simulator by read from raw binary data file
i = pyctpmdif.test_tickdfile('./data/IF1008-20100810.dat', 100)
print 'simulator thread id is', i   #zero is no error
#

while True:
	tickdata = pyctpmdif.newdata()
	if tickdata is not None :
		print tickdata.LastPrice, tickdata.Volume, tickdata.ftime
	usleep(100)


pyctpmdif.stop()

